//
//  simController.h
//  roversimulator
//
//  Created by Matt Roman on 8/11/08.
//  Copyright 2008 University of Oklahoma. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "definitions.h"
#import <OpenGL/gl.h>
#import <OpenGL/glext.h>
#import <OpenGL/glu.h>
#import "Crate.h"
#import "rngs.h"
#import "rvgs.h"

typedef	struct _eye {
	Point3D viewPosition;
	Vector3D viewDirection;
	Vector3D viewUp;
	Vector3D rotateCenter;
	GLfloat pitch,roll,yaw;
	GLfloat	zoom;
	GLdouble aperture;
	GLint viewWidth, viewHeight;
} eye;

@interface simController : NSOpenGLView
{
	eye						camera;
	int						camView;
	NSPoint					mousePoint;
	int						gridStep;
	
	Vector3D				*groundNormals;
	Point3D					*groundPlane;
	float					nOffset;
	float					mOffset;
	float					nGridSize;
	float					mGridSize;
	int						vertexCount;
	
	NSTimer					*timer;
	IBOutlet NSTextField	*cursorPosition;
	IBOutlet NSTextField	*mapScale;
	float					loopTime;
	float					ticksPerMeter;
	
	Point3D			botPos;
	frameVectors	botFrame;
	wayPoint		*WPList;
	Point3D			frontLeft,frontRight,rearLeft,rearRight;
	float			pitch,roll,heading;
	
	int				xbcTime;
	int				leftEncoder,rightEncoder;
	float			leftSpeed,rightSpeed;
	
	BOOL			beamsOn;
	laserScanner	*bodyLaser;
	int				*simBodyData;
	Point3D			*BLPoints;
	
	laserScanner	*panelLaser;
	int				*simPanelData;
	Point3D			*PLPoints;
	
	laserScanner	*profileLaser;
	int				*simProfileData;
	Point3D			*PROLPoints;
	
	// rover geometry
	GLuint		aWheel;
	GLuint		suspension;
	GLuint		laserCase;
	GLdouble	leftWheelSpin;
	GLdouble	rightWheelSpin;
	
	// tools panel
	IBOutlet NSPanel	*toolsPanel;
	IBOutlet NSSlider	*degslider;
	IBOutlet NSSlider	*xslider;
	IBOutlet NSSlider	*yslider;
	IBOutlet NSSlider	*zslider;
	IBOutlet NSTextField *d,*xs,*ys,*zs;
	
	// obstacles
	NSMutableArray		*blocks;
	NSMutableArray		*localBlocks;
}

+ (NSOpenGLPixelFormat*) basicPixelFormat;
- (id) initWithFrame: (NSRect) frameRect;
- (void)drawFrame;
- (void)drawRect:(NSRect)bounds;

- (void)setWPList:(wayPoint*)wp;
- (float)pitch;
- (float)roll;
- (float)heading;

- (int)xbcTime;
- (int)leftEncoder;
- (int)rightEncoder;
- (void)setSpeedLeft:(float)ls right:(float)rs;

- (void)bodyLaserUpdate;
- (void)panelLaserUpdate;
- (void)profileLaserUpdate;
- (void)getLasers:(laserScanner*)body panel:(laserScanner*)panel profile:(laserScanner*)profile;
- (void)drawLaserBeams:(BOOL)q;
- (IBAction)showTools:(id)sender;
- (IBAction)openFile:(id)sender;
- (void)loadTerrainFromFile:(NSString*)filename;
- (void)randomizeObstacles;
@end
